package com.poster.entity.vo;

import com.poster.enums.ResultCode;
import lombok.Data;

@Data
public class ResultVo<T> {


    private Integer code;

    private String msg;

    private T data;

    public ResultVo() {
    }

    public ResultVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> ResultVo<T> create(){
        return new ResultVo<>();
    }

    public static <T> ResultVo<T> create(Integer code, String msg){
        return new ResultVo<>(code, msg);
    }

    public static <T> ResultVo<T> success() {
        return ResultVo.<T>create()
                .setResultCode(ResultCode.SUCCESS);
    }

    public static <T> ResultVo<T> success(T data) {
        return ResultVo.<T>create()
                .setResultCode(ResultCode.SUCCESS)
                .setData(data);
    }

    public static <T> ResultVo<T> error(ResultCode resultCode) {
        return ResultVo.<T>create()
                .setResultCode(resultCode);
    }

    public static <T> ResultVo<T> error(ResultCode resultCode, T data) {
        return ResultVo.<T>create()
                .setResultCode(resultCode)
                .setData(data);
    }

    public ResultVo<T> setResultCode(ResultCode code) {
        this.code = code.code();
        this.msg = code.message();
        return this;
    }


    public ResultVo<T> setData(T data) {
        this.data = data;
        return this;
    }

}
